<script type='text/javascript' src="<?php echo $this->basePath('public/css/dbblack/js/artdialog/artDialog.js?skin=simple'); ?>"></script>
<script type='text/javascript' src="<?php echo $this->basePath('public/css/dbblack/js/artdialog/plugins/iframeTools.js'); ?>"></script>
<link type="text/css" rel="stylesheet" href="<?php echo $this->basePath('public/css/dbblack/css/product.css'); ?>" />
<script type='text/javascript' src="<?php echo $this->basePath('public/css/dbblack/js/jquery.enlarge.js'); ?>"></script>

<div class="bg-base">
    <ol class="bread-crumb container">
        <li><a href="<?php echo $this->url('shopfront/default'); ?>"><?php echo $this->translate('首页'); ?></a></li>
        <?php if($this->class_menu) { foreach($this->class_menu as $menu_val) {
            if($menu_val['class_id'] != $this->class_info->class_id) {
                ?>
        <li>
            <a href="<?php echo $this->url('frontgoodslist/default', array('class_id'=>$menu_val['class_id'])); ?>"><?php echo $this->escapeHtml($menu_val['class_name']); ?></a>
        </li>
            <?php } } } ?>
        <li><?php echo $this->class_info->class_name; ?></li>
    </ol>
</div>
<div class="container">
    <div class="goods-detail mt10 clearfix" style="position: relative;">

        <?php
        $goodsclass_goodslist_top_banner = $this->frontwebsite()->getShopAd('goodsclass', 'goodslist_top_banner', 'pc', $this->class_info->class_id);
        if($goodsclass_goodslist_top_banner != '') {
            echo $goodsclass_goodslist_top_banner;
        }
        ?>

        <div class="content">
            <?php
            $tag_c_str    = $this->tag_c != ''  ? '&tag_c=' . $this->tag_c   : '';
            $sort_c_str   = $this->sort_c != '' ? '&sort_c=' . $this->sort_c : '';
            $sort_tag_str = $tag_c_str . $sort_c_str;

            ?>
            <div id="selector">
                <div class="spec-attr box">
                    <h2><span class="red" ><?php echo $this->class_info->class_name; ?></span></h2>

                    <dl class="attr clearfix">
                        <dt class="attr-key"><?php echo $this->translate('同级分类'); ?>：</dt>
                        <dd class="attr-value">
                            <?php foreach ($this->current_class as $curr_class_val) { if($curr_class_val['class_state'] == 0) continue; ?>
                                    <a href="<?php echo $this->url('frontgoodslist/default', array('class_id'=>$curr_class_val['class_id'])); ?>" <?php if($curr_class_val['class_id'] == $this->class_info->class_id) echo 'class="select"'; ?> ><?php echo $this->escapeHtml($curr_class_val['class_name']); ?><i></i></a>
                            <?php } ?>
                        </dd>
                    </dl>
                    <?php if($this->sub_class) { ?>
                        <dl class="attr clearfix">
                            <dt class="attr-key"><?php echo $this->translate('下级分类'); ?>：</dt>
                            <dd class="attr-value">
                                <?php foreach($this->sub_class as $sub_class_val) { if($sub_class_val['class_state'] == 0) continue; ?>
                                    <a href="<?php echo $this->url('frontgoodslist/default', array('class_id'=>$sub_class_val['class_id'])); ?>" ><?php echo $this->escapeHtml($sub_class_val['class_name']); ?></a>
                                <?php } ?>
                            </dd>
                        </dl>
                    <?php } ?>

                    <?php if ($this->goods_tag_group) { foreach($this->goods_tag_group as $tag_group_key => $tag_group) { ?>
                    <dl class="attr clearfix">
                        <dt class="attr-key"><?php echo $tag_group; ?>：</dt>
                        <dd class="attr-value">
                            <a class="<?php if (!isset($this->s_tag[$tag_group_key])) echo 'select'; ?>" href="?tag_id=<?php echo '|' . $tag_group_key . $tag_c_str; ?>"><?php echo $this->translate('全部'); ?></a>
                            <?php if ($this->goods_tag[$tag_group_key]) {
                            foreach($this->goods_tag[$tag_group_key] as $tag_val) {
                            ?>
                            <a href="?tag_id=<?php echo $tag_val['tag_id'] . '|' . $tag_group_key . $sort_tag_str; ?>" <?php if(isset($this->s_tag[$tag_group_key]) and $this->s_tag[$tag_group_key] ==$tag_val['tag_id']) echo 'class="select"'; ?> ><?php echo $tag_val['tag_name']; ?><i></i></a>
                            <?php } } ?>
                        </dd>
                    </dl>
                    <?php } } ?>
                </div>
                <div id="select-more">
                    <div class="attr-extra"><div></div></div>
                </div>
            </div>

            <div class="mt10 product_show  product-list  clearfix">
                <div class="clearfix" >
                    <div class="sort-bar">
                        <span><?php echo $this->translate('排序'); ?>：</span>
                        <?php
                        $price_sort = 'ASC';
                        $price_sort_class = '';
                        if (isset($this->sort_selected) and ($this->sort_selected == 'goods_shop_priceASC' or $this->sort_selected == 'goods_shop_priceDESC')) {
                            if($this->sort_selected == 'goods_shop_priceASC') {
                                $price_sort = 'DESC';
                                $price_sort_class = 'class="current-2"';
                            }
                            if($this->sort_selected == 'goods_shop_priceDESC') {
                                $price_sort = 'ASC';
                                $price_sort_class = 'class="current"';
                            }
                        }
                        $time_sort = 'ASC';
                        $time_sort_class = '';
                        if(!isset($this->sort_selected)) $time_sort_class = 'class="current"';
                        if (isset($this->sort_selected) and ($this->sort_selected == 'goods_add_timeASC' or $this->sort_selected == 'goods_add_timeDESC')) {
                            if($this->sort_selected == 'goods_add_timeASC') {
                                $time_sort = 'DESC';
                                $time_sort_class = 'class="current-2"';
                            }
                            if($this->sort_selected == 'goods_add_timeDESC') {
                                $time_sort = 'ASC';
                                $time_sort_class = 'class="current"';
                            }
                        }
                        $click_sort = 'ASC';
                        $click_sort_class = '';
                        if (isset($this->sort_selected) and ($this->sort_selected == 'goods_clickASC' or $this->sort_selected == 'goods_clickDESC')) {
                            if($this->sort_selected == 'goods_clickASC') {
                                $click_sort = 'DESC';
                                $click_sort_class = 'class="current-2"';
                            }
                            if($this->sort_selected == 'goods_clickDESC') {
                                $click_sort = 'ASC';
                                $click_sort_class = 'class="current"';
                            }
                        }
                        ?>
                        <a href="?time_sort=<?php echo $time_sort.$sort_tag_str; ?>" <?php echo $time_sort_class; ?> ><?php echo $this->translate('默认'); ?><i class="ie6png"></i></a>
                        <a href="?price_sort=<?php echo $price_sort.$sort_tag_str; ?>" <?php echo $price_sort_class ?> ><?php echo $this->translate('价格'); ?><i class="ie6png"></i></a>
                        <a href="?click_sort=<?php echo $click_sort.$sort_tag_str; ?>" <?php echo $click_sort_class; ?> ><?php echo $this->translate('人气'); ?><i class="ie6png"></i></a>
                    </div>
                </div>
                <dl>
                    <dd>
                        <ul class="clearfix">
                            <?php
                            $goodsIdStr = '';
                            if ($this->goods_list->getTotalItemCount() > 0) { foreach ($this->goods_list as $goods_value) {
                                $goodsIdStr .= $goods_value['goods_id'] . ',';
                                ?>
                                <li>
                                    <dl class="product">
                                        <dt class="img">
                                            <a href="<?php echo $this->url('frontgoods/default', array('goods_id'=>$goods_value['goods_id'], 'class_id'=>$this->class_info->class_id)); ?>" title="<?php echo $this->escapeHtml($goods_value['goods_name']); ?>">
                                                <img alt="<?php echo $this->escapeHtml($goods_value['goods_name']); ?>" src="<?php echo $this->basePath($this->frontwebsite()->shopGoodsImage($goods_value['goods_thumbnail_image'])); ?>" width="220">
                                            </a>
                                        </dt>
                                        <dd class="title list_title"><a title="<?php echo $this->escapeHtml($goods_value['goods_name']); ?>" href="<?php echo $this->url('frontgoods/default', array('goods_id'=>$goods_value['goods_id'], 'class_id'=>$this->class_info->class_id)); ?>"><?php echo $this->escapeHtml($goods_value['goods_name']); ?></a></dd>
                                        <dd><span class="price" id="goods_price_<?=$goods_value['goods_id']?>"><?php
                                                $goodsPrice = (isset($goods_value['group_price']) and $goods_value['group_price'] > 0) ? $goods_value['group_price'] : $goods_value['goods_shop_price'];
                                                echo $this->frontwebsite()->shopPriceExtend($goodsPrice);
                                                ?></span></dd>
                                        <dd class="product-ext">
                                            <a href="<?php echo $this->url('frontgoods/default', array('goods_id'=>$goods_value['goods_id'], 'class_id'=>$this->class_info->class_id)); ?>" id="add-cart" class="btn btn-main" style="padding:6px 20px;"><?php echo $this->translate('商品详情'); ?></a>&nbsp;&nbsp;&nbsp;&nbsp;
                                            <a href="javascript:;" class="attention btn btn-info fr" val="<?php echo $goods_value['goods_id']; ?>"><i class="icon-hart-16 ie6png"></i><span><?php echo $this->translate('收藏'); ?></span></a>
                                        </dd>
                                    </dl>
                                </li>
                            <?php } } ?>

                </ul>
                </dd>
                </dl>
            </div>
            <div class="page-nav">
                <?php echo ( count($this->goods_list) > 0 ) ? $this->paginationControl($this->goods_list, 'Sliding', 'site/dbpage',array('page_url'=>$this->url('frontgoodslist/default',array('class_id'=>$this->class_info->class_id)))) : ""; ?>
            </div>
        </div>
    </div>
</div>

<script>
    var attr_extra = '';
    $(".attr").each(function(i){
        var self = $(this);
        if(i>3){
        }
        if(self.find(".attr-value").get(0).scrollHeight>self.height()){
            var span = $("<div class='o-more'><?php echo $this->translate('更多'); ?><b></b></div>");
            self.append(span);
            if(self.find('.select').size()>0){
                span.html('<?php echo $this->translate('收起'); ?><b></b>');
                span.parent().addClass("unflod");
            }
            span.on("click",function(){
                if($(this).text()=='<?php echo $this->translate('更多'); ?>'){
                    $(this).html('<?php echo $this->translate('收起'); ?><b></b>');
                    $(this).parent().addClass("unflod");
                }
                else {
                    $(this).html('<?php echo $this->translate('更多'); ?><b></b>');
                    $(this).parent().removeClass("unflod");
                }
            });
        }
    });

    attr_extra = $(".attr:gt(3) .attr-key").text();
    attr_extra = $.trim(attr_extra);
    attr_extra = attr_extra.replace(/：/gi,'、');
    attr_extra = attr_extra.replace(/、$/gi,'');
    if($(".attr:gt(3)").size()>0){

        if($(".attr:gt(3)").find(".select").size()>0){
            $(".attr:gt(3)").css("display","block");
            $(".attr-extra div:eq(0)").html('<?php echo $this->translate('收起'); ?><b></b>');
            $(".attr-extra").addClass("unflod");
        }else{
            $(".attr:gt(3)").css("display","none");
            $(".attr-extra div:eq(0)").html('<?php echo $this->translate('更多选项'); ?>（'+attr_extra+'）<b></b>');
            $(".attr-extra").removeClass("unflod");
        }
    }else{
        $("#select-more").css("display","none");
    }
    $(".attr-extra:eq(0)").on("click",function(){
        if($(".attr:hidden").size()>0){
            $(".attr:gt(3)").css("display","block");
            $(".attr-extra div:eq(0)").html('<?php echo $this->translate('收起'); ?><b></b>');
            $(".attr-extra").addClass("unflod");
        }else{
            $(".attr:gt(3)").css("display","none");
            $(".attr-extra div:eq(0)").html('<?php echo $this->translate('更多选项'); ?>（'+attr_extra+'）<b></b>');
            $(".attr-extra").removeClass("unflod");
        }

    })

    $(".attention").on("click",function(){
        var id = $(this).attr("val");
        $.post("<?php echo $this->url('frontuser/default',array('action'=>'addFavorites')); ?>",{goods_id:id,class_id:<?php echo $this->class_info->class_id; ?>},function(data){
            if(data=='true') {
                art.dialog.tips("<p class='success'><?php echo $this->translate('该商品成功加入收藏！'); ?></p>");
            } else {
                if(data == 'login_false') {
                    art.dialog.tips("<p class='warning'><?php echo $this->translate('您还没有登录，无法收藏商品！'); ?></p>");
                } else if (data == 'goods_exists') {
                    art.dialog.tips("<p class='success'><?php echo $this->translate('您已经收藏过该商品！'); ?></p>");
                } else {
                    art.dialog.tips("<p class='warning'><?php echo $this->translate('商品收藏不成功！'); ?></p>");
                }
            }
        })
    })
</script>
<?php if(defined('FRONT_CACHE_STATE') and FRONT_CACHE_STATE == 'true') { ?>
    <script>
        $.post('<?php echo $this->url('frontgoodslist/default',array('action'=>'ajaxGoodsGroupPrice')); ?>',{goodsIdStr:'<?=$goodsIdStr?>'}, function(data){
            if(data.state == 'true') {
                for (var i = 0; i < data.list.length; i++) {
                    $('#goods_price_'+data.list[i].id).html(data.list[i].price);
                }
            }
        },'json');
    </script>
<?php } ?>
